package com.txq.bilibili.app.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.txq.bilibili.app.R;
import com.txq.bilibili.app.model.AlwaysContent;

import java.util.List;

/**
 * Created by yun on 2015/3/24.
 */
public class SocialGridViewAdapter extends BaseAdapter {

    private Context context;
    private List<AlwaysContent>data;

    public SocialGridViewAdapter(Context context, List<AlwaysContent> data){
        this.context=context;
        this.data=data;
    }
    @Override
    public int getCount() {
        int ret=0;
        if(data!=null){
            ret=data.size();
        }
        return ret ;
    }

    @Override
    public Object getItem(int position) {
        Object ret=null;
        if(data!=null){

            ret=data.get(position);
        }
        return ret;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        View ret=null;
        LayoutInflater inflater=LayoutInflater.from(context);

        if(convertView==null) {
            ret = inflater.inflate(R.layout.fragment_social_head_view_gridview_item, parent, false);

        }else{
            ret=convertView;
        }
        ViewHolder holder=(ViewHolder)ret.getTag();

        if(holder== null){
            holder=new ViewHolder();
            holder.titleTxt=(TextView)ret.findViewById(R.id.fragment_social_grid_view_item_title_txt);

            ret.setTag(holder);
        }

        AlwaysContent alwaysContent=data.get(position);

        Log.d("....adapter.",alwaysContent.getTitle());
        holder.titleTxt.setText(alwaysContent.getTitle());

        return ret;
    }

    public class ViewHolder{

        private TextView titleTxt;

    }
}
